/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.renren.io
 *
 * 版权所有，侵权必究！
 */

package com.zzy.gulimall.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Configuration //标注为一个配置类
public class MyCorsConfig {

    @Bean //添加到容器中
    public CorsWebFilter corsWebFilter(){

        System.out.println("准备处理跨域问题。。。。。。。。。");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();

        CorsConfiguration corsConfiguration = new CorsConfiguration();
//    1.配置跨域
        corsConfiguration.addAllowedHeader("*");// 设置允许跨域的请求头
        corsConfiguration.addAllowedMethod("*"); // 设置允许的方法
        corsConfiguration.addAllowedOriginPattern("*"); //设置允许跨域请求的域名
        corsConfiguration.setAllowCredentials(true); //是否允许携带cookie请求

        source.registerCorsConfiguration("/**",corsConfiguration);
        System.out.println("开始处理跨域问题。。。。。。。。。");
        return new CorsWebFilter(source);
    }
}


